from core.security import get_password_hash
from crud.base_crud import CRUDBase
from models import AdminUser
from schemas.admin_schemas.admin_schema import AdminUserCreate, AdminUserUpdate


class CRUDAdminUser(CRUDBase[AdminUser]):

    async def create_admin_user(self, obj_in: AdminUserCreate):

        db_obj = await self.create(obj_in=obj_in, update={
            "hashed_password": get_password_hash(obj_in.password)
        })
        return db_obj

    async def update_admin_user(self,  obj_current: AdminUser, obj_new: AdminUserUpdate):
        obj_current.hashed_password = get_password_hash(obj_new.password)
        db_obj = await self.update(obj_current=obj_current, obj_new=obj_new)
        return db_obj


curd_admin_user = CRUDAdminUser(AdminUser)
